const app = getApp();
import util from '../../../utils/util.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    refresh: false,
    pageEnd: false,
    param: {
      pageNumber: 1,
      pageSize: 10
    },
    list: []
  },
  user(e) {
    var that = this;
    var id = e.currentTarget.dataset.createuid;
    var name = e.currentTarget.dataset.name;
    wx.navigateTo({
      url: '/pages/myCardNew/myCardNew?type=visitor&id=' + id + '&name=' + name,
    })
  },
  org(e) {
    console.log('org')
    var dataset = e.currentTarget.dataset;
    wx.navigateTo({
      url: '/pages/orgHome/orgHome?id=' + dataset.orgid
    })
  },
  addorgbtn(){
    wx.navigateTo({
      url: '/pages/recommendOrg/recommendOrg'
    })
  },
  addorgbtn1() {
    wx.navigateTo({
      url: '/pages/creat/creat'
    })
  },
  activityDetail: function (e) {
    var that = this;
    that.toggle('refresh', true)
    var id = e.currentTarget.dataset.id;
    var type = e.currentTarget.dataset.type;
    var actType = e.currentTarget.dataset.acttype;
    var orgid = e.currentTarget.dataset.orgid;
    if (type == 0) {
      wx.navigateToMiniProgram({
        appId: app.globalData.activityMiniAppId,
        envVersion: app.globalData.activityMiniEnvVersion,
        path: '/pages/register/register?id=' + id,
        success(res) {
          console.log(res);
        }
      })
    }else{
      wx.navigateTo({
        url: '/pages/contentDetails/contentDetails?id=' + id 
      })
    }
    console.log(id, type, actType)
  },
  list: function (append) {
    var that = this;
    var param = that.data.param
    app.req({
      url: "orgmini/home/dynamicList",
      data: param,
      success: function (res) {
        if (200 == res.code) {
          var now = new Date()
          // var year = now.getFullYear()
          console.log(now)
          var list = res.data.rows
          if (!list || list.length < param.pageSize) {
            that.toggle("pageEnd", true);
          }
          that.toggle("list", append ? that.data.list.concat(list) : list);
          console.log(that.data.list) 
        }
      }
    });
  },
  toggle(type, val) {
    this.setData({
      [type]: val
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    if (!that.data.refresh) {
      app.getUserInfo(function (userInfo) {
        that.toggle("param.pageNumber", 1);
        that.toggle("pageEnd", false);
        that.list();
      });
    }

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    var that = this;
    app.getUserInfo(function (userInfo) {
      that.toggle("param.pageNumber", 1);
      that.toggle("pageEnd", false);
      that.list();
    });
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    if (!that.data.pageEnd) {
      that.toggle("param.pageNumber", that.data.param.pageNumber + 1);
      that.list(true);
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})